package team.stu.polygongame.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import team.stu.polygongame.domain.PolygonGameData;
import team.stu.polygongame.method.DpGameImg;
import team.stu.polygongame.method.PolygonGeneration;


@RestController
public class PolygonController {


    @PostMapping("/data")
    ResponseEntity<Object> getData(@RequestBody int n) {
        PolygonGeneration polygonGeneration = new PolygonGeneration();
        PolygonGameData data = new PolygonGameData();
        data.setPoint(polygonGeneration.pointGeneration(n));
        data.setVector(polygonGeneration.vectorGeneration(n));
        return new ResponseEntity<>(data, HttpStatus.OK);
    }

    @PostMapping("/dynamic")
    ResponseEntity<Object> Dynamic(@RequestBody String[] array) {
        PolygonGeneration polygonGeneration = new PolygonGeneration();
        String[] strings = polygonGeneration.divideAndRanking(array);
        DpGameImg dpGameImg = new DpGameImg();
        int[] data = dpGameImg.DP_main(strings);
        String[] str = new String[array.length/2 + 1];
        for (int i = 0; i <data.length ; i++) {
            str[i] = data[i]+"";
        }
        return new ResponseEntity<>(str, HttpStatus.OK);
    }


}
